import os

def timeOrder(file):
    dataDict = {}
    with open("data_"+file+".txt","r")as f:
        for i in f.readlines():
            tempList = i.split()
            if len(tempList) == 4:
                # print(i)
                # print(i.split())
                firstStr=i
                workerNu=i.split()[0]
                taskNu = i.split()[1]
            else:
                dataDict.update({int(tempList[0]):tempList})
    data = sorted(dataDict)
    
    folderNu=[2,3,4,5,6,7,8,9,10,20]
    for foNu in folderNu:
        destPath = "../EverySender_cap"+str(foNu)
        if not os.path.exists(destPath):
            os.mkdir(destPath)

        outputFileName = os.path.join(destPath,"data_"+file+"_s.txt")
        #修改总共节点数
        firstLine = firstStr.split()
        firstLine[3] = str(int(firstLine[0])*foNu+int(firstLine[1]))
        tempStr = ''
        for item in firstLine:
            tempStr +=item+' '
        tempStr+='\n'
        with open(outputFileName,'w') as f:
            f.write(tempStr)
            for i in data:
                outstr = ''
                nodeType = dataDict[i][1]
                if nodeType=="w":
                    dataDict[i][5]=str(foNu)
                for j in dataDict[i]:
                    outstr +=j+' '
                outstr+='\n'
                f.write(outstr)
        #     # print(dataDict[i])
        
        # outstr=str(taskNu)+"\t"+str(workerNu)+'\n'
        # f.write(outstr)
        # for i in data:
        #     outstr = ''
        #     if dataDict[i][1]=='w':
        #         outstr=dataDict[i][0]+'\t'+dataDict[i][1]+'\t'+dataDict[i][2]+'\t'+dataDict[i][3]+'\t'+dataDict[i][6]+'\t'+dataDict[i][4]
        #     elif dataDict[i][1]=='t':
        #         outstr=dataDict[i][0]+'\t'+dataDict[i][1]+'\t'+dataDict[i][2]+'\t'+dataDict[i][3]+'\t'+dataDict[i][4]
        #     outstr+='\n'
        #     f.write(outstr)

if __name__=='__main__':
    fileName=["00","01","02","03","04","05","06","07","08","09"]
    for i in fileName:
        timeOrder(i)